const WordEntity = require('../pages/beans/WordEntity').WordEntity;
function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds();


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function hasWordEntityOfArray(arr, obj) {
  for (let index = 0; index < arr.length; index++) {
    var element = arr[index];
    if(element.word === obj.word && element.content === obj.content && element.symbol === obj.symbol && element.sound === obj.sound) {
      return true;
    }
  }
  return false;
}


function refushPassFlag4ArrayElement(arr, word, level,isPass) {
  for (let index = 0; index < arr.length; index++) {
    var element = arr[index];
    if(element.word === word && element.level === level) {
      element.isPass = isPass;
      arr.splice(index,1,element);
      return true;
    }
  }
  return false;
}



module.exports = {
  formatTime: formatTime,
  hasWordEntityOfArray: hasWordEntityOfArray,
  refushPassFlag4ArrayElement: refushPassFlag4ArrayElement,
  wordBook: 'wordBook',
  remoteWordList: 'remoteWordList',
  loginUserInfo: 'loginUserInfo',
  // 实际学习天数
  studiedDays: 'days',
  // 计划学习天数
  planStudyDays: 'planStudyDays',
  // 单词类型 4-四级 6-六级
  wordType: 'wordType',
  // 每天计划学习单词数
  planStudyWordsOfDay: 'planStudyWordsOfDay',
  // 每天计划复习单词个数
  planReviewWordsOfDay: 'planReviewWordsOfDay'
}
